package com.zdth.wxpush.config;

import lombok.Data;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author Z-7
 * @Date 2022/8/29
 */
@Data
@Configuration
@ConfigurationProperties(prefix = "wx")
public class WxConfig {

    private String appID;

    private String appsecret;

    /**
     * 今日天气
     */
    private String weatherTemplate;

    /**
     * 热搜
     */
    private String topSearchTemplate;

    /**
     * 天气预报
     */
    private String forecastTemplate;

    /**
     * 舔狗日记
     */
    private String dogTemplate;

    /**
     * 星座解析
     */
    private String constellationTemplate;

    @Bean
    public WxMpService wxMpService() {
        WxMpServiceImpl wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(configStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage configStorage() {
        WxMpDefaultConfigImpl wxMpDefaultConfig = new WxMpDefaultConfigImpl();
        wxMpDefaultConfig.setAppId(appID);
        wxMpDefaultConfig.setSecret(appsecret);
        return wxMpDefaultConfig;
    }
}
